<template>
  <div>
    <!-- 商品信息列表 -->
    <div>
      <el-table :data="data.rows" border style="width: 100%">
        <el-table-column type="expand">
          <template slot-scope="scope">
            <el-form label-position="left" class="demo-table-expand">
              <el-form-item label="商品 ID">
                <span>{{ scope.row._id }}</span>
              </el-form-item>
              <el-form-item label="用户 ID">
                <span>{{ scope.row.userId._id }}</span>
              </el-form-item>
              <el-form-item label="商品描述">
                <span>{{ scope.row.desc }}</span>
              </el-form-item>
            </el-form>
          </template>
        </el-table-column>
        <el-table-column label="用户名" align="center" width="150">
          <template slot-scope="scope">
            {{ scope.row.userId.userName }}
          </template>
        </el-table-column>
        <el-table-column prop="name" label="商品名称" align="center">
        </el-table-column>
        <el-table-column
          prop="price"
          label="商品价格"
          align="center"
          width="150"
        >
        </el-table-column>

        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <!-- 点击商品在对应的商品留言 -->
            <el-button
              size="mini"
              type="primary"
              @click="$router.push('/example/send/' + scope.row._id)"
              >留言</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import goodsApi from "../../api/goods";
import Moment from "moment";
import config from "../../utils/config";
export default {
  data() {
    return {
      data: {
        page: 1,
        limit: 10,
        total: 0,
        maxPage: 0,
        rows: [],
      },
      goods: {},
      query: "",
      resource_server: config["resource_server"],
    };
  },
  //调用获取商品信息
  created() {
    this.getGoods();
  },
  methods: {
    time(time) {
      return Moment(time).format();
    },
    img(path) {
      return this.resource_server + path;
    },
    //获取商品信息
    async getGoods() {
      const data = await goodsApi.get({
        page: this.data.page,
        limit: this.data.limit,
        query: {},
        sort: {
          check: -1,
        },
      });
      Object.assign(this.data, data);
    },
  },
};
</script>
